{% extends 'base.html' %}
{% block title %}
定时任务
{% endblock %}

{% block content %}
<div class="btn-group">
    <button type="button" class="btn btn-info">{{ product.name }}</button>
    <button type="button" class="btn btn-primary dropdown-toggle btn-sm" data-toggle="dropdown">
        <span class="caret"></span>
        <span class="sr-only">切换下拉菜单</span>
    </button>
    <ul class="dropdown-menu" role="menu">
        {% for pd in products %}
        <li><a href="{{ url_for('wx.job.crontab_view',pk=pd.id) }}">{{ pd.name }}</a></li>
        {% endfor %}
    </ul>
</div>
<br>
<br>
<!-- 
<div style="float: right">
    <button type="button" class="btn btn-outline-info" data-toggle="modal" data-target="#myModal">添加新的定时任务</button>
</div>

<h5>定时任务</h5>
<br>
模态框
<div class="modal fade" id="myModal">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">添加环境</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <div class="modal-body">
                <h4 class="mb-3">添加一个新的环境</h4>
                <form method="post" action="">
                    <div class="mb-3">
                        <label for="name" class="form-label">任务类型<label style="color: red;">*</label></label>
                        <select class="form-control" id="trigger" name="trigger">
                            {% for cron in crontab %}
                            <option value="{{ cron[0] }}">{{ cron[1] }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="mb-3">
                        <label for="url" class="form-label">任务编号<label style="color: red;">*</label></label>
                        <input type="text" class="form-control" id="jobid" name="jobid" placeholder="请输入任务ID..."
                            required>
                        <div id="url" class="form-text">选择测试场景</div>
                    </div>
                    <div class="mb-3">
                        <label for="url" class="form-label">运行时间<label style="color: red;">*</label></label>
                        <input type="text" class="form-control" id="jobsecond" name="jobsecond"
                            placeholder="请输入任务运行机制..." required>
                        <div id="url" class="form-text">输入任务运行机制</div>
                    </div>
                    <br>
                    <div class="form-actions well well-sm clearfix">
                        <button type="button" class="btn btn-info" data-dismiss="modal">
                            <i class="fa fa-undo"></i>
                            取消
                        </button>
                        <button type="submit" class="default btn btn-primary hide-xs">
                            <i class="fa fa-save"></i>
                            增加
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
模态框 -->
<br>

<div class="row">
    <div class="col-sm-12">
        <div class="table-responsive">
            <table class="table table-bordered table-striped table-sm">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>定时任务ID</th>
                        <th>args参数</th>
                        <th>kwargs参数</th>
                        <th>任务模式</th>
                        <th>运行间隔</th>
                        <th>实例数</th>
                        <th>下次运行时间</th>
                        <th>开始时间</th>
                        <th>删除</th>
                    </tr>
                </thead>
                <tbody>
                    {% if crontabtask %}
                    {% for task in crontabtask %}
                    <tr>
                        <td><strong class="text-info">{{ task.id }}</strong></td>
                        <td><small class="text-muted">{{ task.task_id }}</small></td>
                        <td><small class="text-info">{{ task.args }}</small></td>
                        <td><small class="text-info">{{ task.kwargs }}</small></td>
                        {% if task.trigger == "cron" %}
                            <td><small class="text-primary">定时任务</small></td>
                        {% elif task.trigger == "date" %}
                            <td><small class="text-primary">一次性任务</small></td>
                        {% elif task.trigger == "interval" %}
                            <td><small class="text-primary">循环任务</small></td>
                        {% else %}
                            <td><small class="text-warning">{{ task.trigger }}</small></td>
                        {% endif %}
                        <td><small class="text-info">{{ task.times }}</small></td>
                        <td><small class="text-info">{{ task.max_instances }}</small></td>
                        <td><small class="text-info">{{ task.next_run_time }}</small></td>
                        <td><small class="text-info">{{ task.start_date }}</small></td>
                        {% if task.task_id %}
                        <td><small class="text-info"><a href="{{ url_for('wx.job.delete_crontab', task_id=task.task_id) }}">删除</a></small></td>
                        {% endif %}
                        <td><small class="text-info"><a href="#">删除</a></small></td>
                    </tr>
                    {% endfor %}
                    {% else %}
                    <p style="color: red">暂无数据</p>
                    {% endif %}

                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}
